#include("../layout.html")
#@layout("个人资料")

#define body()
<h1>个人资料</h1>

<div class="layui-fluid">
	<form class="layui-form" action="/admin/profile/update" action="post">
		<h2>个人设置</h2>
		<div class="layui-form-item">
    		<label class="layui-form-label">可视化编辑器</label>
    		<div class="layui-input-block">
    			<input type="checkbox" name="rich_editing" id="rich_editing" value="false" #(user.rich_editing?'':'checked') title="撰写文章时不使用可视化编辑器" lay-skin="primary">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">语法高亮</label>
    		<div class="layui-input-block">
    			<input type="checkbox" name="syntax_highlighting" id="syntax_highlighting" value="false" #(user.syntax_highlighting?'':'checked') title="在编辑代码时禁用语法高亮" lay-skin="primary">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">管理界面配色方案</label>
    		<div class="layui-input-block">
    			<input type="radio" name="admin_color" id="admin_color_fresh" value="fresh" title="默认" #('fresh' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_light" value="light" title="明亮" #('light' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_blue" value="blue" title="蓝色" #('blue' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_coffee" value="coffee" title="咖啡" #('coffee' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_ectoplasm" value="ectoplasm" title="星质" #('ectoplasm' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_midnight" value="midnight" title="午夜" #('midnight' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_ocean" value="ocean" title="海洋" #('ocean' == user.admin_color?'checked':'')>
    			<input type="radio" name="admin_color" id="admin_color_sunrise" value="sunrise" title="日出" #('sunrise' == user.admin_color?'checked':'')>
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">键盘快捷键</label>
    		<div class="layui-input-block">
    			<input type="checkbox" name="comment_shortcuts" id="comment_shortcuts" value="true" #(user.comment_shortcuts?'checked':'') title="管理评论时启用键盘快捷键。" lay-skin="primary">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">工具栏</label>
    		<div class="layui-input-block">
    			<input type="checkbox" name="admin_bar_front" id="admin_bar_front" value="true" #(user.show_admin_bar_front?'checked':'') title=" 在浏览站点时显示工具栏" lay-skin="primary">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">语言</label>
    		<div class="layui-input-block" style="width:200px;">
    			<select name="locale" id="locale">
    				<option value="site-default" selected="selected">站点默认</option>
					<option value="en_US" lang="en">English (United States)</option>
					<option value="zh_CN" lang="zh">简体中文</option>
				</select>
   	 		</div>
    	</div>
    	
		<h2>姓名</h2>
		<div class="layui-form-item">
    		<label class="layui-form-label">用户名</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="user_login" id="user_login" value="#(user.user_login??)" class="layui-input" disabled="disabled">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">名字</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="first_name" id="first_name" value="#(user.first_name??)" placeholder="" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">姓氏</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="last_name" id="last_name" value="#(user.last_name??)" placeholder="" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">昵称（必填）</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="nickname" id="nickname" value="#(user.nickname??)" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">公开显示为</label>
    		<div class="layui-input-block" style="width:200px;">
    			<select name="display_name" id="display_name">
					<option value="#(user.display_name??)" selected="selected">#(user.display_name??)</option>
					#if(user.display_name != user.user_login)
					<option value="#(user.user_login??)">#(user.user_login??)</option>
					#end
					#if(user.display_name != user.nickname)
					<option value="#(user.nickname??)">#(user.nickname??)</option>
					#end
				</select>
   	 		</div>
    	</div>
    	<h2>联系信息</h2>
    	<div class="layui-form-item">
    		<label class="layui-form-label">电子邮件（必填）</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="email" id="email" value="#(user.user_email??)" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">站点</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="text" name="url" id="url" value="#(user.url??)" placeholder="" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<h2>关于您自己</h2>
    	<div class="layui-form-item">
    		<label class="layui-form-label">个人说明</label>
    		<div class="layui-input-block" style="width:500px;">
    			<textarea name="description" id="description" placeholder="" class="layui-textarea">#(user.description??)</textarea>
   	 			<p class="description">分享关于您的一些信息。可能会被公开。</p>
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">资料图片</label>
    		<div class="layui-input-block">
				<input type="hidden" name="simple_local_avatar" id="simple_local_avatar" value="#(user.simple_local_avatar??)"/>
    			<img alt="" src="#(user.simple_local_avatar??'/assets/admin/css/images/default_avatar.jpeg')" class="avatar avatar-96 photo" height="96" width="96">
   	 			<p class="description">您可以点击上面图片修改您的资料图片。</p>
   	 		</div>
    	</div>
    	
    	<h2>账户管理</h2>
    	<div class="layui-form-item">
    		<label class="layui-form-label">新密码</label>
    		<div class="layui-input-block" style="width:400px;">
    			<input type="password" name="user_pass" id="user_pass" placeholder="不填写，则不修改原密码" autocomplete="off" class="layui-input">
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">会话</label>
    		<div class="layui-input-block">
    			#if(user.session_tokens.size() > 1) 
    			<button type="button" id="destroy-sessions" class="layui-btn layui-btn-sm layui-btn-primary">登出其他设备</button>
    			<p class="description">您丢失了您的手机或是在公共电脑上登录着您的账户？您可以在其他设备上登出，只在此处保留登录状态。</p>
    			#else
    			<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled="disabled">登出其他设备</button>
    			<p class="description">您只有在此处登入。</p>
    			#end
   	 		</div>
    	</div>
    	<div class="layui-form-item">
    		<button type="submit" lay-submit lay-filter="*" class="layui-btn layui-btn-sm">更新个人资料</button>
    	</div>
    	<input type="hidden" name="user_id" id="user_id" value="#(loginUser.ID)">
	</form>
</div>
#end

#define foot()
<script>
layui.cache.page = 'profile';
layui.use(['upload', 'tbynet'], function(){
	var $ = layui.$
	,upload = layui.upload
	,tbynet = layui.tbynet;

	upload.render({
        elem: '.avatar'
        ,url: '/admin/user/avatar'
        ,data: {
        	uid: #(user.ID)
        }
        ,done: function(res){
            layer.msg('上传成功');
            console.log(res)
            $(this.item).attr('src', res.data);
            $('#simple_local_avatar').val(res.data);
        }
    });
});
</script>
#end